package com.kqb.sgadmin.service.pipeline.create.handler;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kqb.sgadmin.model.Admin;
import com.kqb.sgadmin.service.AdminService;
import com.kqb.sgadmin.service.pipeline.create.AdminCreateHandler;
import com.kqb.sgadmin.service.pipeline.create.context.AdminCreateContext;
import com.kqb.sgcommon.base.exception.BusinessException;
import com.kqb.sgcommon.base.utils.ThrowUtils;
import jakarta.annotation.Resource;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author 杉果树皮
 */
@Component
@Order(10)
public class UsernamePhoneValidationHandler implements AdminCreateHandler {
    @Resource
    private AdminService adminService;

    @Override
    public void handle(AdminCreateContext context) {
        String username = context.getUsername();
        String phone = context.getPhone();
        boolean exist = adminService.isExist(username, phone);
        ThrowUtils.throwIf(exist, BusinessException.of("用户名或手机号已存在"));

    }
}
